@extends('backstage.layout.master')
@section('title', '订单详情')
@section('style')

<style>
    .ace-file-input input[type=file]{
        position:static;
    }
    .ace-nav {
        height: 10px;
    }
    #container_id{
        align-content: center;
    }
    .detail-create td{
        background-color: #f5f5f5;
    }
    .detail td{
        background-color: #fff;
    }
    .title td{
        background-color: #f9f9f9;
    }

</style>
@stop
@section('script')
    <script>
        function update_after_state(th,type){

            $.ajax({
                url:"/backstage/order/update-aftermark-state",
                type:"post",
                data:{"state":type,"order_after_id":th},
                datatype:'json',
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        location.reload();
                        return;
                    }
                    swal(re.message,'','warning');
                    return;

                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }

        function changeNeedRefund(th){
            var need_refund         = $("#need_refund option:selected").val();
            //alert(need_refund,after_id);
            $.ajax({
                url:"/backstage/order/change-after",
                type:"post",
                data:{"need_refund":need_refund,"after_id":th},
                datatype:'json',
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        return;
                    }
                    swal(re.message,'','warning');
                    return;

                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }

        function changeIsRefund(th){
            var is_refund           = $("#is_refund option:selected").val();
            //alert(is_refund,after_id);
            $.ajax({
                url:"/backstage/order/change-after",
                type:"post",
                data:{"is_refund":is_refund,"after_id":th},
                datatype:'json',
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        return;
                    }
                    swal(re.message,'','warning');
                    return;

                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }

        function updte_result_desc(th){
            swal('处理中','请稍后','warning');
            var back_mes    = $("#back_mes").val();
            $.ajax({
                url:"/backstage/order/update-result-desc",
                type:"post",
                data:{'order_after_id':th,'result_desc':back_mes},
                datatype:"json",
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        location.reload();
                        return;
                    }
                    swal(re.message,'','warning');
                    return;
                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }

        function updbackremark(th){
            var back_remark = $("#back_remark").val();
            $.ajax({
                url:"/backstage/order/update-aftermark-back-remark",
                type:"post",
                data:{'order_after_id':th,'back_remark':back_remark},
                datatype:"json",
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        return;
                    }
                    swal(re,message,'','warning');
                    return;
                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }
        function updexchange(th){
            var send_express_id = $("#send_express_id").val();
            var send_order_express_id = $("#send_order_express_id").val();

            $.ajax({
                url:"/backstage/order/system-resend-express",
                type:"post",
                data:{'order_after_id':th,'send_express_id':send_express_id,'send_order_express_id':send_order_express_id},
                datatype:"json",
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        return;
                    }
                    swal(re.message,'','warning');
                    return;
                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }
        function createDown(){
            var order_after_id    = $("#order_after_id").val();
            $.ajax({
                url:"/backstage/order/create-after-zip",
                type:"post",
                data:{"order_after_id":order_after_id},
                datatype:"json",
                success:function(re){
                    if(re.state=="M00000"){
                        window.location.href=re.result.url;
                        return;
                    }
                    swal(re.message,'','warning');
                    return;
                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }
        function close_worksheet(th){
            var order_id    = $("#order_id").val();
            $.ajax({
                url:"/backstage/order/close-worksheet",
                type:"post",
                data:{"order_id":order_id,"worksheet_id":th},
                datatype:'json',
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        location.reload();
                        return;
                    }
                    swal(re.message,'','warning');
                    return;
                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }
    </script>

@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>
        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="/" target="_blank">主页</a>
            </li>
            <li class="active">
                <a href="/backstage/order/aftermarks">售后列表</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        售后
                        <small>
                            <i class="icon-double-angle-right"></i>
                            售后单详情
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="table-responsive">
                            <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                <tr class="title">
                                    <td colspan="6">订单基本信息</td>
                                </tr>
                                <tr class="detail">
                                    <td style="width:138px;">订单编号</td>
                                    <td colspan="5">
                                        <a target="_blank" href="/backstage/order/order-detail?order_id={{isset($after->order_id)?$after->order_id:''}}">
                                            {{isset($after->order_id)?$after->order_id:''}}
                                        </a>
                                        <input type="hidden" id="order_after_id" value="{{isset($after->order_after_id)?$after->order_after_id:''}}"/>
                                    </td>
                                    <div class="col-sm-9" style="display:none;">
                                        <input type="text" id="order_id" class="col-xs-10 col-sm-5" value="{{isset($after->order_id)?$after->order_id:''}}" readonly="true"/>
                                    </div>
                                </tr>
                                <tr class="detail">
                                    <td style="width:138px;">用户编号</td>
                                    <td colspan="5">
                                        <a target="_blank" href="/backstage/user/userdetail?user_id={{isset($after->user_id)?$after->user_id:''}}" title="点击查看用户详情" style="cursor:pointer;">
                                            {{isset($after->user_id)?$after->user_id:''}}
                                        </a>
                                    </td>
                                </tr>

                                <tr>
                                    <td>支付方式</td>
                                    <td colspan="1">

                                        @if(isset($after->pay_type)&&$after->pay_type==0)
                                        未支付
                                        @elseif(isset($after->pay_type)&&$after->pay_type==1)
                                        支付宝
                                        @elseif(isset($after->pay_type)&&$after->pay_type==2)
                                        微信
                                        @elseif(isset($after->pay_type)&&$after->pay_type==3)
                                        优惠券
                                        @endif

                                    </td>
                                    <td>第三方支付交易号</td>
                                    <td colspan="3">
                                        {{isset($after->trade_no)?$after->trade_no:''}}
                                    </td>
                                </tr>
                                <tr>
                                    <td>订单总价</td>
                                    <td colspan="1">
                                        {{isset($after->total_price)?$after->total_price:''}}
                                    </td>
                                    <td>订单实际支付金额</td>
                                    <td colspan="3">
                                        {{isset($after->total_fee)?$after->total_fee:''}}
                                    </td>
                                </tr>
                                <tr>
                                    <td>工单号</td>
                                    <td colspan="1">
                                        {{isset($after->worksheet_id) ? $after->worksheet_id : ''}}
                                    </td>
                                    <td>工单状态</td>
                                    <td colspan="3">
                                        @if(isset($after->worksheet_id) &&
                                            $after->worksheet_id != '' &&
                                            isset($after->enabled_worksheet) &&
                                            $after->enabled_worksheet)
                                        有效 &nbsp
                                        <button onclick="close_worksheet('{{isset($after->worksheet_id) ? $after->worksheet_id : ''}}')">
                                            关闭工单
                                        </button>
                                        @elseif(isset($after->worksheet_id) &&
                                                $after->worksheet_id == '' )
                                        未绑定工单
                                        @else
                                        已关闭
                                        @endif
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="6">收货信息</td>
                                </tr>
                                <tr>
                                    <td>姓名</td>
                                    <td colspan="1">

                                        {{isset($after->rece->consignee) ? $after->rece->consignee : ''}}

                                    </td>
                                    <td>联系电话</td>
                                    <td colspan="3">

                                        {{isset($after->rece->phone) ? $after->rece->phone : ''}}

                                    </td>
                                </tr>
                                <tr>
                                    <td>收货地址</td>
                                    <td colspan="5">

                                        {{isset($after->rece->address)?$after->rece->address:''}}

                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="6">
                                        售后单信息
                                    </td>
                                </tr>
                                <tr>
                                    <td>售后编号</td>
                                    <td colspan="1">
                                        <a>{{isset($after->order_after_id)?$after->order_after_id:''}}</a>
                                    </td>
                                    <td>售后类型</td>
                                    <td colspan="3">
                                        @if(isset($after->type) && $after->type == 1)
                                        退货
                                        @elseif(isset($after->type) && $after->type == 2)
                                        换货
                                        @else
                                        未知
                                        @endif
                                    </td>
                                </tr>
                                <tr>
                                    <td>售后状态</td>
                                    <td colspan="5">
                                        @if(isset($after->after_state) && $after->after_state==1)
                                            审核中
                                        @elseif(isset($after->after_state) && $after->after_state==2)
                                            审核通过
                                        @elseif(isset($after->after_state) && $after->after_state==0)
                                            审核未通过
                                        @elseif(isset($after->after_state) && $after->after_state==3)
                                            返货中
                                        @elseif(isset($after->after_state) && $after->after_state==4)
                                            官方已收货
                                        @elseif(isset($after->after_state) && $after->after_state==5)
                                            处理中
                                        @elseif(isset($after->after_state) && $after->after_state==6)
                                            官方已寄回
                                        @elseif(isset($after->after_state) && $after->after_state==7)
                                            买家已收货
                                        @else
                                            未知
                                        @endif
                                    </td>
                                </tr>

                                <tr>
                                    <td colspan="6">售后单详情</td>
                                </tr>
                                <tr>
                                    <td>作品图片</td>
                                    <td>产品模版名称 | 品牌 | 产品编号</td>
                                    <td>颜色 | 尺码</td>
                                    <td>单价</td>
                                    <td>申请数量</td>
                                </tr>
                                @if(isset($after->goods) && isset($after->goods['vaild']))
                                @foreach ($after->goods['vaild'] as $detail)
                                <tr class="detail-create">
                                    <td width="230px">
                                        <a href="{{isset($detail->original_image[0])?$detail->original_image[0]:''}}" download="">
                                            <img src="{{isset($detail->thumbnail[0])?$detail->thumbnail[0]:''}}"
                                            title="作品预览图" width="100px"/>
                                        {{isset($detail->order_detail_number) ? $detail->order_detail_number : ''}}
                                    </td>
                                    <td>
                                        <a href="/backstage/products/detail/{{isset($detail->product_id)?$detail->product_id:''}}" title="点击查看产品信息">
                                        {{isset($detail->product_temp_name) ? $detail->product_temp_name : ''}} |
                                        {{isset($detail->brand_name) ? $detail->brand_name : ''}} |
                                        {{isset($detail->product_id) ? $detail->product_id : ''}}
                                        </a>
                                    </td>
                                    <td>
                                        {{isset($detail->colour_name)?$detail->colour_name:''}} | {{isset($detail->size_name)?$detail->size_name:''}}
                                    </td>
                                    <td>
                                        {{isset($detail->preferential_price)?$detail->preferential_price:''}}
                                    </td>
                                    <td>
                                        {{isset($detail->quantity)?$detail->quantity:''}}
                                    </td>
                                </tr>
                                @endforeach
                                <tr>
                                    <td colspan="6"><a class="btn" onclick="createDown()">下载打印图片包</a><a id="download"></a></td>
                                </tr>
                                @else
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                </tr>
                                @endif
                                <tr>
                                    <td>申请原因</td>
                                    <td colspan="5">
                                        {{isset($after->reason_desc) && $after->reason_desc != '' ? pack('H*', $after->reason_desc) : ''}}
                                    </td>
                                </tr>
                                <tr>
                                    <td>用户上传素材图</td>
                                    <td colspan="5">
                                    @if(isset($after->images)&&count($after->images)>0)
                                    @foreach($after->images as $image)
                                        <a href="{{isset($image->original_image)?$image->original_image:''}}" download="">
                                            <img src="{{isset($image->thumbnail)?$image->thumbnail:''}}" width="200px" height="250px">
                                        </a>
                                    @endforeach
                                    @endif
                                    </td>
                                </tr>
                                @if(isset($after->after_state) && $after->after_state==1)
                                <tr>
                                    <td>审核结果</td>
                                    <td colspan="5">
                                        <button onclick="update_after_state('{{isset($after->order_after_id) ? $after->order_after_id : ''}}',2)">
                                        通过
                                        </button>
                                        &nbsp &nbsp
                                        <button onclick="update_after_state('{{isset($after->order_after_id) ? $after->order_after_id : ''}}',0)">
                                        未通过
                                        </button> *请先填写审核描述再点击审核结果按钮
                                    </td>
                                </tr>
                                @elseif(isset($after->after_state) && $after->after_state > 1)
                                <tr>
                                    <td>审核结果</td>
                                    <td colspan="5">
                                        通过
                                    </td>
                                </tr>
                                @elseif(isset($after->after_state) && $after->after_state == 0)
                                <tr>
                                    <td>审核结果</td>
                                    <td colspan="5">
                                        未通过
                                    </td>
                                </tr>
                                @endif
                                @if(isset($after))
                                <tr>
                                    <td>审核描述</td>
                                    <td colspan="5">
                                        <textarea class="form-control" name="back_mes" id="back_mes" >{{isset($after->result_desc) && $after->result_desc != '' ? pack('H*',$after->result_desc) : ''}}</textarea>
                                        <button onclick="updte_result_desc('{{isset($after->order_after_id)?$after->order_after_id:''}}')">
                                        修改审核结果
                                        </button>
                                        *需要换行的地方请填写\n , 例：第一行\n第二行 ,不明白可修改后见页面底部的处理进度
                                    </td>
                                </tr>
                                @endif
                                <!-- <tr>
                                    <td>用户要求发货时间</td>
                                    <td colspan="4">
                                        <input type="text" id="send_time" style="width:190px;" value="{{isset($result->order->user_send_time)?$result->order->user_send_time:''}}"
                                        class="col-xs-10 col-sm-5"
                                        readonly="true"/>
                                    </td>
                                </tr> -->
                                <tr>
                                    <td colspan="6">用户回寄信息</td>
                                </tr>
                                <tr>
                                    <td>配送方式</td>
                                    <td colspan="5">
                                        {{isset($after->express_name) ? $after->express_name : ''}}
                                    </td>
                                </tr>

                                <tr>
                                    <td>快递单号</td>
                                    <td colspan="5">
                                        {{isset($after->order_express_id)?$after->order_express_id:''}}
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        官方收货状态
                                    </td>
                                    <td colspan="5">
                                        @if(isset($after->after_state) && $after->after_state >= 0 && $after->after_state <=3)
                                        未收货 &nbsp&nbsp
                                        <button onclick="update_after_state('{{isset($after->order_after_id) ? $after->order_after_id : ''}}',4)">
                                            确认收货
                                        </button>
                                        @else
                                        已收货
                                        @endif
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        官方状态核实
                                    </td>
                                    <td colspan="5">
                                        @if(isset($after->after_state) && $after->after_state >= 0 && $after->after_state <=4)
                                        未核实 &nbsp&nbsp
                                        <button onclick="update_after_state('{{isset($after->order_after_id) ? $after->order_after_id : ''}}',5)">
                                            确认核实
                                        </button>
                                        @else
                                            已核实
                                        @endif
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="6">寄出信息</td>
                                </tr>
                                <tr>
                                    <td>配送方式</td>
                                    <td colspan="5">
                                        <select id="send_express_id">
                                            @if(isset($express)&&isset($after->send_express_id))
                                            @foreach($express as $exp)
                                            @if($exp->express_id==$after->send_express_id)
                                            <option value ="{{$exp->express_id}}" selected = "selected">{{$exp->express_name}}</option>
                                            @else
                                            <option value ="{{$exp->express_id}}">{{$exp->express_name}}</option>
                                            @endif
                                            @endforeach
                                            @endif
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>快递单号</td>
                                    <td colspan="5">
                                        <input type="text" id="send_order_express_id" style="width:190px;" value="{{isset($after->send_order_express_id)?$after->send_order_express_id:''}}"
                                        class="col-xs-10 col-sm-5">
                                        <button onclick="updexchange('{{isset($after->order_after_id)?$after->order_after_id:''}}')">修改换货寄出信息</button>
                                    </td>
                                </tr>
                                <tr>
                                    <td>申请时间</td>
                                    <td colspan="5">
                                        {{isset($after->created_at)?date('Y-m-d H:i:s',$after->created_at):''}}
                                    </td>
                                </tr>
                                <tr>
                                    <td>后台备注</td>
                                    <td colspan="5">
                                        <textarea class="form-control" name="back_remark" id="back_remark" >{{empty($after->back_remark)?'':pack('H*',$after->back_remark)}}</textarea>
                                        <button onclick="updbackremark('{{isset($after->order_after_id)?$after->order_after_id:''}}')">修改后台备注</button>
                                    </td>
                                </tr>
                            </table>
                            <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                <tr>
                                    <td colspan="3">
                                        处理进度
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        状态标题
                                    </td>
                                    <td>
                                        内容
                                    </td>
                                    <td>
                                        时间
                                    </td>
                                </tr>
                                @if(isset($after->process))
                                @foreach($after->process as $process)
                                <tr>
                                    <td>
                                        {{ isset($process->title) ? $process->title : ''}}
                                    </td>

                                    <td>
                                        <?php
                                            if(isset($process->message)){
                                                $str = explode('\n',$process->message);
                                                $new = implode('<br>', $str);
                                            }else{
                                                $new = '';
                                            }
                                        ?>
                                        {!!$new!!}
                                    </td>
                                    <td>
                                        {{isset($process->time_str) ? $process->time_str : ''}}
                                    </td>
                                </tr>
                                @endforeach
                                @endif
                            </table>
                        </div>
                    </div>
                </div>
            </div>
                <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</div><!-- /.page-content -->
@stop
